package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueInfoVO;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;
    @Transactional
    @Override
    public String add(ClueTrackRecordVo tbClueTrackRecord) {
        //获得当前操作人
        String username = SecurityUtils.getUsername();
        //将数据复制到TbClueTrackRecord
        TbClueTrackRecord trackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord,trackRecord);

        //补充需要添加的数据
        trackRecord.setCreateBy(username);
        trackRecord.setType("0");
        //添加跟进记录
        tbClueTrackRecordMapper.add(trackRecord);

        //根据ID查找出该对象当前信息
        TbClue tbClue=tbClueMapper.selectTbClueById(tbClueTrackRecord.getClueId());
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        //修改线索表记录
        tbClueMapper.updateTbClue(tbClue);
        return "操作成功";
    }

    /**
     * 查询线索跟进记录列表
     */
    @Override
    public TableDataInfo list(Long clueId) {
        List<TbClueTrackRecord> list=tbClueTrackRecordMapper.list(clueId);
        TableDataInfo info = new TableDataInfo();
        info.setRows(list);
        info.setMsg("查询成功");
        info.setCode(200);
        return info;
    }

    @Override
    public void add1(TbClueTrackRecord trackRecord) {
        tbClueTrackRecordMapper.add1(trackRecord);
    }
}
